<template>
<div class="main">
   <van-cell  title="培训计划"  v-model="PlanName"/>
   <van-cell  title="培训类型" v-model ="TrainTypeName" />
   <div class="block2" />
   <van-cell  title="开始时间" v-model ="PlanStartTime" />
   <van-cell  title="结束时间" v-model ="PlanFinishTime" />
   <van-cell  title="发布人" v-model ="PublishChnName" />
   <van-cell  title="发布时间" v-model ="PublishDate" />
   <van-cell  title="说明" v-model="Introduce" />
<div class="btn_submit">
        <van-button block type="info" @click="btnJoin" v-show="AllowJoin||AllowBrowse"> {{AllowJoin?"加入培训":"查看详情"}} </van-button>
      </div>
   </div>
</template>

<script>
import {  Dialog } from "vant";
export default {
  components: {},
  data() {
    return {
		PlanName:"安全培训计划",
    TrainTypeName:"培训类型",
    PlanStartTime:"开始时间",
    PlanFinishTime:"结束时间",
    PublishChnName:"发布人",
    PublishDate:"发布时间",
    Introduce:"说明",
    AllowJoin:false,
    AllowBrowse:false,
    PlanCode:"",

    code:"",
    ID :"",
    codeType:"",
    };
  },
  created() {
     if (this.$route.query.PlanCode) {
       this.code = this.$route.query.PlanCode
     }
     if(this.$route.query.CodeType){
       this.codeType = this.$route.query.CodeType;
     }
    this.GetSimpleInfo();
  },
  
  methods: {
    btnJoin(){
      if(this.AllowJoin){
        this.Join()
      }else{
        this.$router.push({path: "/Train/TrainingplanDetail",
        query: { id: this.ID }});
      }
  },
    GetSimpleInfo(){
      
      let parameter = {
        id:0,
        code:this.code,
        //如果从页面获取到code值  取用this.code
        //code:"TP21012800002"
        
      };
      var url = "/TrainPlan/GetSimpleInfo";
      if(this.codeType == "TrainPlanLevel3Safety"){
        url = "/TrainPlan/GetLevel3SafetySimpleInfo";
      }
      let _this = this;
      _this.$axios
      .get(url,{params:parameter})
      .then((res)=>{
        _this.PlanName = res.data.PlanName
        _this.TrainTypeName = res.data.TrainTypeName
        _this.PlanStartTime = res.data.PlanStartTime
        _this.PlanFinishTime = res.data.PlanFinishTime
        _this.PublishChnName = res.data.PublishChnName
        _this.PublishDate = res.data.PublishDate
        _this.Introduce = res.data.Introduce
        _this.AllowJoin = res.data.AllowJoin
        _this.AllowBrowse = res.data.AllowBrowse
        _this.PlanCode = res.data.PlanCode
        _this.ID = res.data.ID
      })
    },
    Join(){
      let parameter = {
         code:this.PlanCode,
         isCheck : true
      };
      let _this = this;
      _this.$axios
      .get("/TrainPlan/Join",{params:parameter})
      .then((res)=>{
        if(res.success){
          //这里应该处理跳转到下个页面或者返回上个页面
          _this.$router.push({
            path: "/Train/TrainingplanDetail",
            query: { id: _this.ID }
          });
        }else{
          if(res.errorType === 11){
            Dialog.confirm({
              title: "提示",
              message: res.errorText
            })
            .then((res1)=>{
              _this.$axios.get("/TrainPlan/Join",{params:{code:this.PlanCode,isCheck:false}})
              .then((res2)=>{
                this.$router.push({
                  path: "/Train/TrainingplanDetail",
                  query: { id: _this.ID }
                });
              })
            })
          }
        }
        
      })
    }
  },
};
</script>

<style lang="less" scoped>
.wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.block {
  width: 120px;
  height: 120px;
  background-color: #fff;
}
.block2 {
  width: 0px;
  height: 10px;
  background-color: #fff;
}
</style>
